import roundTurntable from "./roundTurntable";
import Vue from "vue";
import { Overlay } from "vant";
Vue.use(Overlay);
export default {
  data() {
    return {
      show: false,
      oneShow:false,
      gooodsShow:false,
      // 获取中奖商品信息
      dividendList:[],
      // 获取任务信息
      taskList:[],
      // 判断是否中奖 true中奖 false没中奖
      status:'',
      // 转盘上的奖品数据
      prizeData: [
        {
          id: 1,
          prizeName: "谢谢参与"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/1.png',
        },
        {
          id: 2,
          prizeName: "免单"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/7.png',
        },
        {
          id: 3,
          prizeName: "谢谢参与"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/3.png',
        },
        {
          id: 4,
          prizeName: "免单"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/4.png',
        },
        {
          id: 5,
          prizeName: "谢谢参与"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/5.png',
        },
        {
          id: 6,
          prizeName: "免单"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        },
        {
          id: 7,
          prizeName: "谢谢参与"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        },
        {
          id: 8,
          prizeName: "免单"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        }
      ],
      // 转动的圈数
      rotateCircle: 6,
      // 转动需要持续的时间（s）
      duringTime: 4.5,
      // 转盘样式的选项
      turntableStyleOption: {
        // 背景色
        prizeBgColors: ["#ffffff", "#fab044", "#ffffff", "#fab044", "#ffffff", "#fab044", "#ffffff", "#fab044"],
        // 转盘的外边框颜色
        borderColor: "#fab044"
      },

      // 中奖的奖品的index
      prizeIndex: -1,
      // 用来锁定转盘，避免同时多次点击转动
      isLocking: false,

      // 剩余抽奖次数
      num: 1
    };
  },
  activated() {
    this.getLuckDraw()
  },
  methods: {
    // 关闭弹窗
    close(){
      this.show = false
      this.oneShow = false
      this.gooodsShow = false
    },
    // 获取抽奖数据
    getLuckDraw(){
      $http.post("plugin.free-lottery.frontend.lottery", {
        order_ids:4088,
      }).then(res => {
        console.log(res, "res");
          if (res.result == 1) {
            this.dividendList = res.data.dividend
            this.taskList = res.data.task
            this.status = res.data.status
          } else {
            // Toast(res.msg);
          }
        });
    },
    startRotation() {
      if(this.status){
        // 如果还不可以转动
        if (!this.canBeRotated()) {
          return false;
        }
        // 开始转动
        // 先上锁
        this.isLocking = true;
        // 设置在哪里停下，应该与后台交互，这里随机抽取0~5
        // const index = Math.floor(Math.random() * this.prizeData.length);
        // 成功后次数减少一次
        this.num--;
        // this.prizeIndex = index;

        if(this.status){
          this.prizeIndex = 1
        }else{
          this.prizeIndex = 0
        }
        // 告诉子组件，开始转动了
        this.$refs.roundTurntable.rotate(this.prizeIndex);
      }
    },
    // 已经转动完转盘触发的函数
    endRotation() {
      if(`${this.prizeData[this.prizeIndex].prizeName}` === '谢谢参与'){
        this.show = true
      }
      if(`${this.prizeData[this.prizeIndex].prizeName}` === '免单'){
        if(this.taskList.status === 1){
          // status === 1 为已完成
            this.gooodsShow = true
        }else{
          this.oneShow = true
        }
      }
      // 提示中奖
      // alert(`恭喜您获奖啦,您的奖品是：${this.prizeData[this.prizeIndex].prizeName}---${this.prizeIndex}`);
      // 解锁
      this.isLocking = false;
    },
    // 判断是否可以转动
    canBeRotated() {
      if (this.num <= 0) {
        alert("已经没有次数了！");
        return false;
      }
      if (this.isLocking) {
        return false;
      }
      return true;
    }
  },
  components: { roundTurntable }
};

{/* <script>
import roundTurntable from "./roundTurntable";
import Vue from "vue";
import { Overlay } from "vant";
Vue.use(Overlay);
export default {
  name: "",
  components: {
    roundTurntable
  },
  data() {
    return {
      show: false,
      oneShow:false,
      gooodsShow:false,
      // 转盘上的奖品数据
      prizeData: [
        {
          id: 1,
          prizeName: "谢谢参与1"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/1.png',
        },
        {
          id: 2,
          prizeName: "免单2"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/7.png',
        },
        {
          id: 3,
          prizeName: "谢谢参与3"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/3.png',
        },
        {
          id: 4,
          prizeName: "免单4"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/4.png',
        },
        {
          id: 5,
          prizeName: "谢谢参与5"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/5.png',
        },
        {
          id: 6,
          prizeName: "免单6"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        },
        {
          id: 7,
          prizeName: "谢谢参与7"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        },
        {
          id: 8,
          prizeName: "免单8"
          // prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png',
        }
      ],
      // 转动的圈数
      rotateCircle: 6,
      // 转动需要持续的时间（s）
      duringTime: 4.5,
      // 转盘样式的选项
      turntableStyleOption: {
        // 背景色
        prizeBgColors: ["#ffffff", "#fab044", "#ffffff", "#fab044", "#ffffff", "#fab044", "#ffffff", "#fab044"],
        // 转盘的外边框颜色
        borderColor: "#fab044"
      },

      // 中奖的奖品的index
      prizeIndex: -1,
      // 用来锁定转盘，避免同时多次点击转动
      isLocking: false,

      // 剩余抽奖次数
      num: 10
    };
  },
  methods: {
    // 关闭弹窗
    close(){
      this.show = false
      this.oneShow = false
      this.gooodsShow = false
    },
    startRotation() {
      // 如果还不可以转动
      if (!this.canBeRotated()) {
        return false;
      }
      // 开始转动
      // 先上锁
      this.isLocking = true;
      // 设置在哪里停下，应该与后台交互，这里随机抽取0~5
      const index = Math.floor(Math.random() * this.prizeData.length);
      // 成功后次数减少一次
      this.num--;
      this.prizeIndex = index;
      // 告诉子组件，开始转动了
      this.$refs.roundTurntable.rotate(index);
    },
    // 已经转动完转盘触发的函数
    endRotation() {
      if(`${this.prizeData[this.prizeIndex].prizeName}` === '谢谢参与'){
        this.show = true
      }
      if(`${this.prizeData[this.prizeIndex].prizeName}` === '免单'){
        this.oneShow = true
      }
      // 提示中奖
      alert(`恭喜您获奖啦,您的奖品是：${this.prizeData[this.prizeIndex].prizeName} - ${this.prizeData[this.prizeIndex].id}`);
      // 解锁
      this.isLocking = false;
    },
    // 判断是否可以转动
    canBeRotated() {
      if (this.num <= 0) {
        alert("已经木有次数了！");
        return false;
      }
      if (this.isLocking) {
        return false;
      }
      return true;
    }
  }
};
</script> */}